package org.langqiao.io;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;

import javax.imageio.ImageIO;

public class Capture{
    // 截图并存入文件系统
    public static void captureScreen(String fileName) throws Exception {
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     Rectangle screenRectangle = new Rectangle(screenSize);
     Robot robot = new Robot();
     BufferedImage image = robot.createScreenCapture(screenRectangle);
     ImageIO.write(image, "jpg", new File(fileName));
    } 

	//用法:
   //main方法中(或者你需要的地方):
	public static void main(String[] args){
	   String path = "c:/test.jpg";
	    try {
	    	captureScreen(path);
	    } catch (Exception e) {
	   e.printStackTrace();
	}
}
}